//package com.gcxy.conf.filter;
//
//import com.gcxy.common.StringConstant;
//import com.gcxy.utils.JWTSecurityUtil;
//import com.gcxy.utils.RedisTemplateUtil;
//import com.gcxy.utils.SecurityUtil;
//import com.nimbusds.jose.JOSEException;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//
//import javax.servlet.*;
//import javax.servlet.http.HttpServletRequest;
//import java.io.IOException;
//import java.text.ParseException;
//import java.util.List;
//
//public class JwtFilter implements Filter {
//    @Autowired
//    private RedisTemplateUtil redisTemplateUtil;
//
//    @Value("${jwt.secret}")
//    private List<String> whitelist;
//
//    @Override
//    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//        //放行白名单
//        //1获取当前请求路径和白名单中的路径进行比较
//
//
//        //1.获取请求头中的token
//        HttpServletRequest request = (HttpServletRequest) servletRequest;
//        String jwtToken = request.getHeader(StringConstant.AUTHORIZATION);
//        if (jwtToken == null) {
//            throw new RuntimeException("token不存在!");
//        }
//        //2.jwt工具类进行解析
//        String accountFromJWT=null;
//        try {
//            accountFromJWT = JWTSecurityUtil.checkToken(jwtToken);
//        } catch (Exception e) {
//            e.printStackTrace();
//            throw new RuntimeException("token解析失败！");
//        }
//        //3.从缓存中获取
//        String accountFromRedis = redisTemplateUtil.getString(jwtToken);
//        if (accountFromRedis == null) {
//            throw new RuntimeException("token已过期！");
//        }
//        if (!accountFromJWT.equals(accountFromRedis)) {
//            throw new RuntimeException("token已过期！");
//        }
//        filterChain.doFilter(servletRequest, servletResponse);
//    }
//}
